
public class Node implements Comparable<Node> {
	
	// fields for the node
	private char level;
	private String nodeTitle;
	private int sizeRom;
	private int sizeRam;
	
	// parent nodes
	private Node system = null;
	private Node module = null;
	private Node object = null;
	private Node section = null;
	
	public Node() {
		level = 0;
		nodeTitle = null;
		sizeRom = 0;
		sizeRam = 0;
	}
	
	public Node(char level, String nodeTitle, int sizeRom, int sizeRam) {
		this.level = level;
		this.nodeTitle = nodeTitle;
		this.sizeRom = sizeRom;
		this.sizeRam = sizeRam;
		
        switch(level) {
	        case '1':
	        	system = this;
	        	break;
	        case '2':
	        	module = this;
	        	break;
	        case '3':
	        	object = this;
	        	break;
	        case '4':
	        	section = this;
	        	break;
	        default:
	        	return;
        }
	}

	public Node getSystem() {
		return system;
	}
	
	public void setSystem(Node n) {
		this.system = n;
	}
	
	public Node getModule() {
		return module;
	}
	
	public void setModule(Node n) {
		this.module = n;
	}

	public Node getObject() {
		return object;
	}
	
	public void setObject(Node n) {
		this.object = n;
	}
	
	public Node getSection() {
		return section;
	}
	
	public void setSection(Node n) {
		this.section = n;
	}
	
	public void setSizeRom(int sizeRom) {
		this.sizeRom = sizeRom;
	}
	
	public int getSizeRom() {
		return sizeRom;
	}

	public void setSizeRam(int sizeRam) {
		this.sizeRam = sizeRam;
	}	
	
	public int getSizeRam() {
		return sizeRam;
	}

	public void setLevel(char level) {
		this.level = level;
	}
	
	public char getLevel() {
		return level;
	}
	
	public void setNodeTitle(String nodeTitle) {
		this.nodeTitle = nodeTitle;
	}
	
	public String getNodeTitle() {
		return nodeTitle;
	}
	
	public int hashCode() {
		int result = 17;
		if(nodeTitle != null)
			result = 37 * result + nodeTitle.hashCode();
		result = 37 * result;
		return result;
	}

	public boolean equals(Object o) {
		return o instanceof Node && nodeTitle.equals(((Node)o).getNodeTitle());
	}
		  
	public int compareTo(Node arg) {
	    // Compare by class name first:
	    String first = getClass().getSimpleName();
	    String argFirst = arg.getClass().getSimpleName();
	    
	    int firstCompare = first.compareTo(argFirst);
	    if(firstCompare != 0) return firstCompare;
	    
	    if ( level != 0 && arg.level != 0 ) {
	    	if ( level != arg.level ) return 0; 
	    } else 
	    	return 0;
	    
	    if(nodeTitle != null && arg.nodeTitle != null) {
		    int secondCompare = nodeTitle.compareTo(arg.nodeTitle);
		    if(secondCompare != 0) return secondCompare;
	    } else
	    	return 1;
	    
	    return 0;
	}
	
	public String toString() {	
		//return String.format("%c, [ %-25s ],  ROM-> [ %6d ],  RAM-> [ %6d ], hashCode = %d", level, nodeTitle, sizeRom, sizeRam, hashCode());
		return nodeTitle;
	}
	
}
